package ASWebDavTest 
{
	import ASWebDavTest.BaseFile;
	import mx.collections.ArrayCollection;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	
	public class BaseFile extends EventDispatcher
	{
		protected var beenLoaded:Boolean = false;

		public function BaseFile(parent:BaseFile)
		{
			this.parent = parent;
		}

		protected var parent:BaseFile;
		public function get Parent():BaseFile
		{
			return parent;
		}
		
		public function get Patriarch():BaseFile
		{
			if (Parent == null)
				return this;
			return parent.Patriarch;
		}
		
		public function get RelativePath():String
		{
			return Url.substring(Patriarch.Url.length);
		}
		
		protected var url:String;
		public function get Url():String
		{
			return url;
		}
		public function set Url(value:String):void
		{
			url = value;
		}
		
		public function get Name():String
		{
			throw new Error("Not implemented!");
		}
		
		public function get IsFolder():Boolean
		{
			throw new Error("Not implemented!");
		}
		
		public function get SizeBytes():int
		{
			throw new Error("Not implemented!");
		}

		public function get CreatedUtc():Date
		{
			throw new Error("Not implemented!");
		}
		
		public function get ModifiedUtc():Date
		{
			throw new Error("Not implemented!");
		}
		
		protected var files:Vector.<BaseFile> = new Vector.<BaseFile>();
		public function get Files():Vector.<BaseFile>
		{
			if (beenLoaded == false)
				Load(1);
			return files;
		}
		
		public function get children():ArrayCollection
		{
			var ar:ArrayCollection = new ArrayCollection();
			for each(var child:BaseFile in Files)
				ar.addItem(child);
			return ar;
		}
		
		public function GetFile(otherFile:BaseFile):BaseFile 
		{
			for each (var file:BaseFile in Files)
				if (file.IsFolder == otherFile.IsFolder && file.Name == otherFile.Name)
					return file;
			return null;
		}
		
		public function Load(depth:int):void 
		{
			dispatchEvent(new Event("DataChanged"));
		}
		
	}
}